//全局配置axios
import axios  from "axios";
//创建axios实例 做统一设置
const instance = axios.create({
    baseURL:'/api',//http://localhost:7778/api/dataCity--重写--http://localhost:7777/dataCity
    timeout: 6000
})
//请求拦截器
instance.interceptors.request.use(config =>{
    config.headers.me = 'google';
    return config;
},error =>{
    Promise.reject(error);
})
//响应拦截器
instance.interceptors.response.use(response => {
    return response.data;
},error =>{
    if(error.response && error.response.status){
        let status = error.response.status
        let message = '';
        switch (status) {
            case 400 :
                message = '请求参数格式错误!'
                break;
            case 403 :
                message = '权限不足!'
                break;
            case 404 :
                message = '资源未找到!'
                break;
            case 408 :
                message = '请求超时!'
                break;
            case 500 :
                message = '服务器异常!'
                break;
            default:
                message = '请求失败!'
                break;
        }
        alert('请求失败!');
        return Promise.reject(message+error)
    }
})




export default instance